#include<stdio.h>
int n,k,a[1001],s[1001][1001],trace[1001][1001];
int max=0;
void input(){
    FILE *fp=fopen("CHIAK.INP","r");
    fscanf(fp,"%d%d",&n,&k);
    for(int i=1;i<=n;i++){
        fscanf(fp,"%d",&a[i]);
    }
    fclose(fp);
}
int tru(int a,int b){
    int t=(a-b)%k;
    if(t>0)return t;
    else return t+k;
}
void proccessing(){
    for(int i=1;i<=n;i++){
        for(int j=0;j<k;j++){        
            if(s[i-1][j]>s[i-1][tru(j,a[i])]+1){
                trace[i][j]=-j;
                s[i][j]=s[i-1][j]; 
            }
            else{
                trace[i][j]=tru(j,a[i]);
                s[i][j]=s[i-1][tru(j,a[i])]+1;
            }
        }
        if(s[i][0]>s[max][0])max=i;
    }
}
void output(){
    FILE *fp=fopen("CHIAK.OUT","w");
    int h=0;
    for(int i=max;i>=1;i--){
        if(trace[i][max]>0){
            fprintf(fp,"%d  ",a[i]);
            max=trace[i][max];
        }else max=-trace[i][max];  
    }
    fclose(fp);
}
int main(){
    input();
    proccessing();
    output();
    return 0;
}
